package com.zbf.并发包;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.Semaphore;

/**
 * @author: LI-CI-GAO
 * 作者: licigao
 * 日期: 2021/8/16  15:49
 * 描述:
 */
public class TestBingFaBao {

    public static void main(String[] args) throws InterruptedException {

          //测试CountDownLounch
         // TestBingFaBao.testCountDowan();

        // TestBingFaBao.cycliber();

         TestBingFaBao.semphonne();

    }



    public static void semphonne(){

        Semaphore semaphore=new Semaphore(1);

        for (int i=0;i<10;i++){
            MySemphoneThread mySemphoneThread = new MySemphoneThread(semaphore);
            mySemphoneThread.start();
        }

    }


    /**
     * 作者: LI-CI-GAO
     * 日期: 2021/8/16  16:10
     * 描述: 
     * @Param []
     * @Return void
     */
    public static void cycliber(){


        CyclicBarrier cyclicBarrier=new CyclicBarrier(3);

        MyCycThread myCycThread1=new MyCycThread(cyclicBarrier,"A",1000L);
        MyCycThread myCycThread2=new MyCycThread(cyclicBarrier,"B",5000L);
        MyCycThread myCycThread3=new MyCycThread(cyclicBarrier,"C",3000L);

        myCycThread1.start();
        myCycThread2.start();
        myCycThread3.start();


        LinkedBlockingQueue linkedBlockingQueue=new LinkedBlockingQueue();


    }


    /**
     * 作者: LI-CI-GAO
     * 日期: 2021/8/16  15:59
     * 描述: 测试CountDowan
     * @Param []
     * @Return void
     */
    public static void testCountDowan() throws InterruptedException {

        CountDownLatch countDownLatch=new CountDownLatch(3);

        MyThread myThread=new MyThread(countDownLatch);
        myThread.start();
        MyThread myThread2=new MyThread(countDownLatch);
        myThread2.start();
        MyThread myThread3=new MyThread(countDownLatch);
        myThread3.start();

        countDownLatch.await();

        System.out.println("===========走出发了 啦啦啦");

        MyThread myThread5=new MyThread(countDownLatch);
        myThread5.start();
        MyThread myThread6=new MyThread(countDownLatch);
        myThread6.start();
        MyThread myThread7=new MyThread(countDownLatch);
        myThread7.start();

        countDownLatch.await();

        System.out.println("------------------------------");

    }


}
